using NodeCanvas.BehaviourTrees;
using NodeCanvas.Framework;
using Snake.Gameplay;
using Snake.Logger;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;

public class TestGameplayTag : MonoBehaviour, IDragHandler
{
    [SerializeField] private GameplayAbilityComponent abilityComponent;
    [SerializeField] private BehaviourTreeOwner ai;

    private bool _isMoving;

    private void Start()
    {
        GameplayCueContainer.CueDefines =
            AssetDatabase.LoadAssetAtPath<GameplayCueDefine>("Assets/CueDefine.asset").data;
        abilityComponent.AbilitiesContainer.GiveAbility(
            AssetDatabase.LoadAssetAtPath<GameplayAbility>("Assets/Ability/GA_NormalAttack.asset"));
        ai.graph.blackboard.AddVariable<GameplayAbilityComponent>("ASC").SetValue(abilityComponent);
    }

    private void Update()
    {
        ai.UpdateBehaviour();
        if (Input.GetKeyDown(KeyCode.Space))
        {
            abilityComponent.EffectsContainer.AddEffect(GameplayFactory.CreateEffectSpec(AssetDatabase
                .LoadAssetAtPath<
                    GameplayEffect>("Assets/TestEffect.asset")));

            Log.Info(abilityComponent.AttributeSet["Health"].Value);
        }

        var input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        if (input.sqrMagnitude > 0f)
        {
            if (!_isMoving)
            {
                abilityComponent.TagContainer.AddTag("Actor.State.Move");
                _isMoving = true;
            }
        }
        else
        {
            if (_isMoving)
            {
                abilityComponent.TagContainer.RemoveTag("Actor.State.Move");
                _isMoving = false;
            }
        }
    }


    public void OnDrag(PointerEventData eventData)
    {
        Log.Info("drag");
    }
}